package com.hxt.framework.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @ClassName: HashCrypto
 * @Description: 加密
 * @author: 
 * @date: 2016年10月18日 上午10:57:09
 */
public class HashCrypto {

	public static String encrypt(String v) {
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(v.getBytes());
			byte b[] = md.digest();
			byte[] b2 = new byte[8];
			for (int i = 0; i < b2.length; i++)
				b2[i] = (byte) (b[i] ^ b[i + 8]);
			String ret = HexUtil.bin2hex(b2);
			return ret;
		} catch (Exception e) {
			return v;
		}
	}

	/**
	 * @Title: MD5
	 * @Description: MD5 32位
	 * @param sourceStr
	 * @return
	 * @return: String
	 */
	public static String encrypt32(String sourceStr) {
		String result = "";
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(sourceStr.getBytes());
			byte b[] = md.digest();
			int i;
			StringBuffer buf = new StringBuffer("");
			for (int offset = 0; offset < b.length; offset++) {
				i = b[offset];
				if (i < 0)
					i += 256;
				if (i < 16)
					buf.append("0");
				buf.append(Integer.toHexString(i));
			}
			result = buf.toString().toLowerCase();
		} catch (NoSuchAlgorithmException e) {
			System.out.println(e);
		}
		return result;
	}

	public static String getToken() {
		return UuidUtils.getUUid();

	}

	public static void main(String[] args) {
		// String pass="888888";
		// if(args.length>0){
		// //System.out.println("crypto password");
		// pass=args[0];
		// }
		//
		// String p=encrypt(pass);
		// System.out.println(pass+"===>"+p);
		// System.out.println(getToken());
		System.out.println(encrypt32("000000"));

	}
}
